<?php

/**
 * Application Model DbTables
 *
 * @package Application_Model
 * @subpackage DbTable
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Table definition for users
 *
 * @package Application_Model
 * @subpackage DbTable
 * @author <YOUR NAME HERE>
 */
class Application_Model_DbTable_Users extends Application_Model_DbTable_TableAbstract
{
    /**
     * $_name - name of database table
     *
     * @var string
     */
    protected $_name = 'users';

    /**
     * $_id - this is the primary key name
     *
     * @var int
     */
    protected $_id = 'idusers';

    protected $_sequence = true;

    protected $_referenceMap = array(
        'FkUsersUsers' => array(
          	'columns' => 'idpere',
            'refTableClass' => 'Application_Model_DbTable_Users',
            'refColumns' => 'idusers'
        ),
        'FkUsersTypeusers1' => array(
          	'columns' => 'idtypeusers',
            'refTableClass' => 'Application_Model_DbTable_Typeusers',
            'refColumns' => 'idtypeusers'
        ),
        'FkUsersGoverneras1' => array(
          	'columns' => 'idgoverneras',
            'refTableClass' => 'Application_Model_DbTable_Governeras',
            'refColumns' => 'idgoverneras'
        ),
        'FkUsersFonctionresp1' => array(
          	'columns' => 'idfonctionresp',
            'refTableClass' => 'Application_Model_DbTable_Fonctionresp',
            'refColumns' => 'idfonctionresp'
        )
    );
    protected $_dependentTables = array(
        'Droitfeuille',
        'Fichiertransferet',
        'Users',
        'Usersprojets'
    );

	public function select_user($idpere=""){
		$selector=$this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
		
		$selector->setIntegrityCheck(false);
		
		$selector->columns(
								array(	"idgoverneras"=>"governeras.idgoverneras"
										
										,"monidusers"=>"users.idusers"
						    			,"monnom"	=>"users.nom"
						    			,"monprenom"	=>"users.prenom"
						    			,"monidtypeusers"=>"users.idtypeusers" 
						    			,"monidfonctionresp"=>"users.idfonctionresp"
						    			,"monlogin"	=>"users.login"
						    			,"monmotpasse"	=>"users.motpasse"
						    			,"mondelegation"	=>"users.delegation"
						    			,"monemail"	=>"users.email"
						    			,"montel"=>"users.tel"
										,"nompere"=>"u.nom"
										,"prenompere"=>"u.prenom"
										));
		
		$selector->joinInner(array("u"=>"users"), "u.idusers=users.idpere");
		$selector->joinInner("governeras", "governeras.idgoverneras=users.idgoverneras");
		
		if(!empty($idpere)){
			$selector->where("users.idpere = ".$idpere);
		}
		 
		return $this->fetchAll($selector)->toArray();
		
	}

}
